<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: list.phtml 4684 2010-08-16 08:44:14Z huuphuoc $
 * @since		2.0.2
 */
?>
<?php 
$this->headTitle($this->translate('menu_list_page_title'));
?>

<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/menu-48x48.png'; ?>" alt=""/>
    <span><?php echo $this->translate('menu_list_breadcrumb'); ?></span>
</div>
<?php
$message = $this->flashMessenger();
if ($message) {
?>
    <div id="message"><ul><?php echo $message; ?></ul></div>
<?php } ?>

<div style="width: 100%;">
         <form id="frmActions" action="" method="post">
            <div id="actions">
                <input type="button" id="btnCreate" class="button" value="<?php echo $this->translate('menu_build_breadcrumb'); ?>" onclick="location = '<?php echo $this->url(array(), 'menu_menu_build'); ?>';"/>
                <input type="submit" id="btnDelete" class="button" value="<?php echo $this->translate('menu_list_action_delete_selected'); ?>"/>
                <input type="hidden" id="hddIDs" value="" name="ids"/>
            </div>
             <div>
                 <span>Language: </span> <?php echo $this->languageSwitcher('flag', str_repeat('&nbsp;', 2)); ?>
             </div>
            <table class="list" cellspacing="0">
                <thead>
                    <tr>
                        <td width="3%">
                            <input type="checkbox" class="chkAll"/>
                        </td>
                        <td width="25%">
                            <?php echo $this->translate('menu_name'); ?>
                        </td>
                        <td width="25%">
                            <?php echo $this->translate('menu_description'); ?>
                        </td>
                        <td width="15%">
                            <?php echo $this->languageSwitcher('flag', str_repeat('&nbsp', 2)); ?>
                        </td>
                        <td width="15%">
                            <?php echo $this->translate('menu_created_date'); ?>
                        </td>
                        <td width="15%">
                            <?php echo $this->translate('menu_action'); ?>
                        </td>
                    </tr>
                </thead>
                <tbody>
                <?php
                        if ($this->numMenus == 0) {
                ?>
                            <tr>
                                <td colspan="4" style="color: #fc0202;">
                                <?php echo $this->translate('menu_list_not_found'); ?>
                                
                        </td>
                    </tr>
                <?php
                        } else {
                            $i = 0;
                            foreach($this->menus as $menu) {
                ?>
                    <tr id="menu-<?php echo $menu->id ?>" <?php if ($i == $this->numMenus - 1) echo 'class="last"'; ?>>
                        <td>
                            <input type="checkbox" class="chkId" value="<?php echo $menu->id; ?>"/>
                        </td>
                        <td><?php echo $menu->name; ?></td>
                        <td><?php echo $menu->description; ?></td>
                        <td>
                            <?php if (($translations = $this->translationItems($menu)) != null) : ?>
                                <?php foreach ($translations as $language => $translation) : ?>
                                      <?php if ($translation == null && $language != $menu->language) : ?>
                                            <?php if (isset($translations[$this->APP_DEFAULT_LANG])) : ?>
                                            <a class="a_helper_action_add" href="<?php echo $this->url(array('source_id' => $translations[$this->APP_DEFAULT_LANG]->id), 'menu_menu_build_localization'); ?>/<?php echo $language; ?>/">&nbsp;</a>
                                            <?php else : ?>
                                            <a class="a_helper_action_add" href="<?php echo $this->url(array(), 'menu_menu_build'); ?>/<?php echo $language; ?>/">&nbsp;</a>
                                            <?php endif; ?>

                                      <?php elseif (($translation == null && $language == $menu->language) || ($translation != null && $translation->id == $menu->id)) : ?>
                                      <a class="a_helper_action_edit" href="<?php echo $this->url(array('id' => $menu->id), 'menu_menu_edit'); ?>/<?php echo $language; ?>/">&nbsp;</a>

                                      <?php elseif ($translation != null && $translation->id != $menu->id) : ?>
                                      <a class="a_helper_action_edit" href="<?php echo $this->url(array('id' => $translation->id), 'menu_menu_edit'); ?>/<?php echo $language; ?>/">&nbsp;</a>
                                      <?php endif; ?>
                                <?php endforeach; ?>
                            <?php else : ?>
                            &nbsp;
                            <?php endif; ?>
                        </td>
                        <td><?php echo date('m-d-Y',strtotime($menu->created_date)); ?></td>
                        <td>
                            <?php if ($this->allow('edit')) {
                            ?>
                                        <a href="<?php echo $this->url(array('id' => $menu->id), 'menu_menu_edit'); ?>" title=""><?php echo $this->translate('menu_list_action_edit'); ?></a>
                            <?php } ?>
                            <?php if ($this->allow('delete')) {?>
                            | <a class="deleteAction" rel="<?php echo $menu->id ?>" href="#" title=""><?php echo $this->translate('menu_list_action_delete'); ?></a>
                            <?php } ?>
                        </td>
                   </tr>
                <?php
                            }
                        }
                ?>
                    </tbody>
                    <tfoot>
                        <tr>
                            <td >
                                <input type="checkbox" class="chkAll"/>
                            </td>
                            <td >
                        <?php echo $this->translate('menu_name'); ?>
                    </td>
                    <td >
                        <?php echo $this->translate('menu_description'); ?>
                    </td>
                    <td >
                        <?php echo $this->languageSwitcher('flag', str_repeat('&nbsp', 2)); ?>
                    </td>
                    <td>
                        <?php echo $this->translate('menu_created_date'); ?>
                    </td>
                    <td>
                        <?php echo $this->translate('menu_action'); ?>
                    </td>
                </tr>
            </tfoot>
        </table>
    </form>
    <?php
    if ($this->numMenus != 0) {        
    ?>
    <div id="paginator">
		<?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions); ?>
    </div>
    <?php
    }
    ?>
</div>


<script type="text/javascript">
$(document).ready(function() {
	<?php if ($this->allow('delete')) : ?>
	$('a.deleteAction').click(function() {
		var self = this;
		$('#confirmDialog').html('<?php echo addslashes($this->translator('menu_list_action_delete_confirm')); ?>')
			.dialog({
				title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
				dialogClass: 't_a_ui_dialog',
				modal: true,
				closeOnEscape: false,
				resizable: false,
				open: function(event, ui) {
					$('.ui-dialog-titlebar-close').hide();
					$(this).parent().find('.ui-dialog-buttonpane button').wrapInner('<span/>');
				},
				buttons: {
					'<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
						$(this).dialog('destroy');
					},
					'<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
						$(this).dialog('destroy');
						$(self).html('').addClass('t_a_ui_helper_loading');
						var id = $(self).attr('rel');
						$.ajaxq('menu', {
							type: 'POST',
							url: "<?php echo $this->url(array(), 'menu_menu_delete'); ?>",
							data: { id: id },
							success: function(response) {
								if ('RESULT_OK' == response) {
									$('#menuRow_' + id).fadeOut('slow');
								}
							}
						});
					}
				}
			});
	});
	<?php endif; ?>
});
</script>
